<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>getURLParameters</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const getURLParameters = url =>
            (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
                (a, v) => (
                    (a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a
                ),
                {}
            );
        console.log(getURLParameters('google.com'));
        console.log(getURLParameters('http://url.com/page?name=Adam&surname=Smith'));
    </script>
</body>

</html>